package com.poetize.plus.entity.vo;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.poetize.plus.entity.po.Friend;
import io.swagger.v3.oas.annotations.media.Schema;

import java.time.LocalDateTime;
import java.util.List;

/**
 * @author zuosy
 * @created 2024/5/14 17:12
 */
public record FriendVO(

        @Schema(description = "ID")
        Long id,

        @Schema(description = "网站名称")
        String name,

        @Schema(description = "网站域名")
        String url,

        @Schema(description = "网站封面")
        String cover,

        @Schema(description = "网站简介")
        String introduction,

        @Schema(description = "友链类型 0:更好；1:普通")
        String type,

        @Schema(description = "是否审核通过")
        Boolean status,

        @Schema(description = "申请时间")
        @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
        LocalDateTime createTime
) {

    /**
     * 实体类转分页
     *
     * @param friend
     * @return
     */
    public static FriendVO convert(Friend friend) {
        return new FriendVO(friend.getId(), friend.getName(), friend.getUrl(), friend.getCover(), friend.getIntroduction(), friend.getType(), friend.getStatus(), friend.getCreateTime());
    }

    /**
     * 实体类集合转分页集合
     *
     * @param friendList
     * @return
     */
    public static List<FriendVO> convertList(List<Friend> friendList) {
        return friendList.stream().map(FriendVO::convert).toList();
    }
}
